package org.jivesoftware.smackx.packet;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import org.jivesoftware.smack.Roster;
import org.jivesoftware.smack.RosterEntry;
import org.jivesoftware.smack.RosterGroup;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smackx.RemoteRosterEntry;

public class RosterExchange
  implements PacketExtension
{
  private List<RemoteRosterEntry> remoteRosterEntries = new ArrayList();

  public RosterExchange()
  {
  }

  public RosterExchange(Roster paramRoster)
  {
    Iterator localIterator = paramRoster.getEntries().iterator();
    while (localIterator.hasNext())
    {
      RosterEntry localRosterEntry = (RosterEntry)localIterator.next();
      addRosterEntry(localRosterEntry);
    }
  }

  public void addRosterEntry(RosterEntry paramRosterEntry)
  {
    ArrayList localArrayList = new ArrayList();
    Iterator localIterator = paramRosterEntry.getGroups().iterator();
    while (localIterator.hasNext())
    {
      localObject = (RosterGroup)localIterator.next();
      localArrayList.add(((RosterGroup)localObject).getName());
    }
    String[] arrayOfString = (String[])localArrayList.toArray(new String[localArrayList.size()]);
    Object localObject = new RemoteRosterEntry(paramRosterEntry.getUser(), paramRosterEntry.getName(), arrayOfString);
    addRosterEntry((RemoteRosterEntry)localObject);
  }

  public void addRosterEntry(RemoteRosterEntry paramRemoteRosterEntry)
  {
    synchronized (this.remoteRosterEntries)
    {
      this.remoteRosterEntries.add(paramRemoteRosterEntry);
    }
  }

  public String getElementName()
  {
    return "x";
  }

  public String getNamespace()
  {
    return "jabber:x:roster";
  }

  public Iterator<RemoteRosterEntry> getRosterEntries()
  {
    synchronized (this.remoteRosterEntries)
    {
      List localList = Collections.unmodifiableList(new ArrayList(this.remoteRosterEntries));
      return localList.iterator();
    }
  }

  public int getEntryCount()
  {
    return this.remoteRosterEntries.size();
  }

  public String toXML()
  {
    StringBuilder localStringBuilder = new StringBuilder();
    localStringBuilder.append("<").append(getElementName()).append(" xmlns=\"").append(getNamespace()).append("\">");
    Iterator localIterator = getRosterEntries();
    while (localIterator.hasNext())
    {
      RemoteRosterEntry localRemoteRosterEntry = (RemoteRosterEntry)localIterator.next();
      localStringBuilder.append(localRemoteRosterEntry.toXML());
    }
    localStringBuilder.append("</").append(getElementName()).append(">");
    return localStringBuilder.toString();
  }
}

/* Location:           D:\hygieia\userclient\common\libs\easemobchat_2.1.8.jar
 * Qualified Name:     org.jivesoftware.smackx.packet.RosterExchange
 * JD-Core Version:    0.6.1
 */